package com.moioo.exam;


/**
 * Idbuild entity.
 * 
 * @author MyEclipse Persistence Tools
 */

public class Idbuild implements java.io.Serializable {

	// Fields

	private String classname;
	private Integer keyvalue;
	private Integer version;

	// Constructors

	/** default constructor */
	public Idbuild() {
	}

	/** full constructor */
	public Idbuild(Integer keyvalue) {
		this.keyvalue = keyvalue;
	}

	// Property accessors

	public String getClassname() {
		return this.classname;
	}

	public void setClassname(String classname) {
		this.classname = classname;
	}

	public Integer getKeyvalue() {
		return this.keyvalue;
	}

	public void setKeyvalue(Integer keyvalue) {
		this.keyvalue = keyvalue;
	}
	public synchronized static Integer get(Class clz)throws Exception{
		Integer rtv = 0;
		IdbuildDAO dao = new IdbuildDAO();
		Idbuild obj = dao.findById(clz.getName());
		if(obj == null){
			obj = new Idbuild();
			obj.setClassname(clz.getName());
			obj.setKeyvalue(18);
			dao.save(obj);
			rtv = 17;
		}else{
			rtv = obj.getKeyvalue();
			obj.setKeyvalue(rtv+1);
			dao.attachDirty(obj);
		}
		return rtv;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
}